package dewu;

import java.util.*;

public class OriginRoot {
    // 计算原根
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = scanner.nextInt();
        int[] nums = new int[len];
        int[] res = new int[len];
        for (int i = 0; i < len; i++) {
            scanner.nextLine();
            nums[i] = scanner.nextInt();
            int path = euler(nums[i] - 1);
            res[i] = path;
        }
        for (int i = 0; i < len; i++) {
            System.out.println(res[i]);
        }
    }

    private static int euler(int n) {
        int eu = n;
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                eu -= eu / i;
                while (n % i == 0) {
                    n /= i;
                }
            }
        }
        if (n > 1) {
            eu -= eu / n;
        }
        return eu;
    }
}